package com.metasoft.flex.dto {
	
	import _2005.extended.metadata.tva.UserInformationTableType;
	import _2005.mpeg7.tva.UsageHistoryType;
	
	import com.metasoft.flex.MetasoftULC;
		
	public class ProfileInfo {
		
		public var userId:String;
		public var firstName:String;
		public var lastName:String;
		public var gender:String;
		public var password:String;
		public var age:String;
		public var email:String;
		public var creditNames:Array;
		public var content:Array;
		public var atmosphere:Array;
		public var audience:Array;
		public var intention:Array;
		public var format:String;
		public var queryInfo:QueryInfo;
		public var oldPassword:String;
		public var usageHistory:UsageHistoryType;
		public var userInformationTable:UserInformationTableType;
		
		
		public function set setUserInformationTable(userInformationTable:UserInformationTableType):void {
			this.userInformationTable = userInformationTable;
		}
		
		public function set setUsageHistory(usageHistoryArray:UsageHistoryType):void {
			this.usageHistory = usageHistory;
		}
		
		
		public function set setOldPassword(firstName:String):void {
			this.firstName = firstName;
		}
		
		
		public function set setFirstName(firstName:String):void {
			this.firstName = firstName;
		}
		
		public function set setLastName(lastName:String):void {
			this.lastName = lastName;
		}
		
		public function set setContent(content:Array):void {
			this.content = content;
		}
		
		public function set setIntention(intention:Array):void {
			this.intention = intention;
		}
		
		public function set setFormat(format:String):void {
			this.format = format;
		}
		
		public function set setAudience(audience:Array):void {
			this.audience = audience;
		}
		
		public function set setAtmosphere(atmosphere:Array):void {
			this.atmosphere = atmosphere;
		}
		
		public function set setPassword(password:String):void {
			this.password = password;
		}
		
		public function set setAge(age:String):void {
			this.age = age;
		}
		
		public function set setCreditNames(creditNames:Array):void {
			this.creditNames = creditNames;
		}
		
		public function set setGender(gender:String):void {
			this.gender = gender;
		}
		
//		public function initQueryInfo():void {
//			this.queryInfo = new QueryInfo();
//			queryInfo.creditNamess = creditNames;
//			queryInfo.content = content;
//		}
		
		public function toProfileXMLString():String {
			var xmlStr:String = new String();
		
			xmlStr = xmlStr.concat("<profile id=\"", userId, "\">", "\n");
			xmlStr = xmlStr.concat("<firstname>", checkNull(firstName) , "</firstname>" , "\n");
			xmlStr = xmlStr.concat("<lastname>", checkNull(lastName) , "</lastname>" , "\n");
			xmlStr = xmlStr.concat("<gender>", checkNull(gender) , "</gender>" , "\n");
			xmlStr = xmlStr.concat("<password>", checkNull(password) , "</password>" , "\n");
			xmlStr = xmlStr.concat("<age>", checkNull(age) , "</age>", "\n");
			xmlStr = xmlStr.concat("<content>");
			if (content != null) {
				for (var genreName:String in content) {
					xmlStr = xmlStr.concat(genreName, MetasoftULC.GenreDelimiter, content[genreName], MetasoftULC.UserDelimiter);
				}

				if (xmlStr.lastIndexOf(",") == xmlStr.length) 
					xmlStr = xmlStr.substring(0, xmlStr.lastIndexOf(",")); 
			}
			
			xmlStr = xmlStr.concat("</content>", "\n");
			xmlStr = xmlStr.concat("<atmosphere>");
			if (atmosphere != null) {
				for (var genreName:String in atmosphere) {
					xmlStr = xmlStr.concat(genreName, MetasoftULC.GenreDelimiter, atmosphere[genreName], MetasoftULC.UserDelimiter);
				}

				if (xmlStr.lastIndexOf(",") == xmlStr.length) 
					xmlStr = xmlStr.substring(0, xmlStr.lastIndexOf(",")); 
			}
			
			xmlStr = xmlStr.concat("</atmosphere>", "\n");
			xmlStr = xmlStr.concat("<audience>");
			if (audience != null) {
				for (var genreName:String in audience) {
					xmlStr = xmlStr.concat(genreName, MetasoftULC.GenreDelimiter, audience[genreName], MetasoftULC.UserDelimiter);
				}

				if (xmlStr.lastIndexOf(",") == xmlStr.length) 
					xmlStr = xmlStr.substring(0, xmlStr.lastIndexOf(",")); 
			}
			
			xmlStr = xmlStr.concat("</audience>", "\n");
			xmlStr = xmlStr.concat("<intention>");
			if (intention != null) {
				for (var genreName:String in intention) {
					xmlStr = xmlStr.concat(genreName, MetasoftULC.GenreDelimiter, intention[genreName], MetasoftULC.UserDelimiter);
				}

				if (xmlStr.lastIndexOf(",") == xmlStr.length) 
					xmlStr = xmlStr.substring(0, xmlStr.lastIndexOf(",")); 
			}
			
			xmlStr = xmlStr.concat("</intention>", "\n");
			xmlStr = xmlStr.concat("<creditnames>");
			if (creditNames != null) {
				xmlStr = xmlStr.concat(creditNames.toString());
			} 
			 xmlStr = xmlStr.concat("</creditnames>", "\n");
			// Construct QueryInfo for getData String 
			
//			initQueryInfo();
			xmlStr = xmlStr.concat("<query><![CDATA[", checkNull(queryInfo.toGetDataXMLString()), "]]></query>", "\n", "</profile>", "\n");
			
			return xmlStr;
		}
		
		private function checkNull(object:String):String {
			if (object == null) return "";
			return object;
		}
		
	}
}